package org.sixtynine.stock.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.sixtynine.stock.entity.Banner;
import org.sixtynine.stock.entity.BaseEntity;
import org.sixtynine.stock.service.GenericService;
import org.sixtynine.stock.service.content.DataManagerService;
import org.sixtynine.stock.service.file.FileDataServiceImpl;
import org.sixtynine.stock.util.SessionBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;

/**
 * abstract controller for front end opperators
 * 
 * @author Thilanka
 *
 */
public class AbstractFrontController {

	@Autowired
	private GenericService genericService;

	@Autowired
	private DataManagerService dataManagerService;

	@Autowired
	private FileDataServiceImpl fileDataServiceImpl;

	/**
	 * show the banner
	 * 
	 * @param modelAndView
	 */
	public void showBannar(ModelAndView modelAndView) {

		List<BaseEntity> banners = genericService.findAll(Banner.class);
		String bannerLocationUrl = fileDataServiceImpl.getBannerLocation();

		modelAndView.addObject("banners", banners);
		modelAndView.addObject("bannerLocationUrl", bannerLocationUrl);
	}

	protected boolean isUserLogged(HttpServletRequest request) {
		SessionBean sessionBean = SessionBean.getInstance(request);
		return (sessionBean.getUser() != null);
	}
}